#include <util.h>

#define MAX_NUM_OF_KEY  8
#define RADIX           10
#define MAX_SPACE       10000

typedef int KeysType;

typedef struct
{
    KeysType keys[MAX_NUM_OF_KEY];
    int iNext;
} SLCell;

typedef struct
{
    SLCell r[MAX_SPACE];
    int keynum;
    int recnum;
} SLList;

typedef int ArrType[RADIX];

void distribute(SLCell *pr, int i, ArrType f, ArrType e)
{
    int i, p, j;

    for (i = 0; i < RADIX; i++)
        f[i] = 0;

    for (p = pr[0].iNext; p; p = pr[p].iNext)
    {
        j = pr[p].keys[i];
        if (f[j] == 0)
            f[j] = p;
        else
           pr[e[j]].iNext = p; 
        e[j] = p;
    }
}

void collect(SLCell *pr, int i, ArrType f, ArrType e)
{

}

void radix_sort(SLList *pL)
{
    int i;
    // f and e point to the first and last node of RADIX sub list
    ArrType f, e;
    // L.r[0] is the head node
    for (i = 0; i < pL->recnum; i++)
        pL->r[i].iNext = i+1;
    pL->r[pL->recnum].iNext = 0;

    for (i = 0; i < pL->keynum; i++)
    {
        distribute();
        collect();
    }
}

int main(int argc, char *argv[])
{

}
